package com.sihan.framework.etm.common.util;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import org.gavaghan.geodesy.Ellipsoid;
import org.gavaghan.geodesy.GeodeticCalculator;
import org.gavaghan.geodesy.GeodeticCurve;
import org.gavaghan.geodesy.GlobalCoordinates;

public class DistanceComputer {

   public static double compute(Point from, Point to) {
        GlobalCoordinates source = new GlobalCoordinates(from.getLatitude(), from.getLongitude());
        GlobalCoordinates target = new GlobalCoordinates(to.getLatitude(), to.getLongitude());
        GeodeticCurve geoCurve = new GeodeticCalculator().calculateGeodeticCurve(Ellipsoid.Sphere, source, target);

        return Math.sqrt(Math.pow(geoCurve.getEllipsoidalDistance(), 2) + Math.pow(from.height - to.height, 2));
    }

    @AllArgsConstructor
    @Builder
    @Data
    public static class Point {
        private double longitude;
        private double latitude;
        private double height;
    }
}
